package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.bean.FleaMenuBean;

import java.util.List;

/**
 * @author: JiangXFei
 * @date: 2017/11/9 0009
 * @content: 菜单适配器
 */

public class FleaMenuGridAdapter extends BaseAdapter {
    Context mContext;
    List<FleaMenuBean> menuBeanList;

    public FleaMenuGridAdapter(Context mContext, List<FleaMenuBean> menuBeanList) {
        this.mContext = mContext;
        this.menuBeanList = menuBeanList;
    }

    @Override
    public int getCount() {
        return menuBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return menuBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_flea_recy_home_menu, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(menuBeanList.get(position).getImg()).into(viewHolder.img);

        viewHolder.tv.setText(menuBeanList.get(position).getName());
        return convertView;
    }

    private class ViewHolder {
        ImageView img;
        TextView tv;

        public ViewHolder(View v) {
            img = v.findViewById(R.id.img_menu);
            tv = v.findViewById(R.id.tv_menu);
        }
    }
}
